<!DOCTYPE HTML>
<html>
<head>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>

<div id="container">
  <button id="aria-label" aria-label="Aria Label">Content</button>
  <button id="title" title="Title">Content</button>
  <button id="labelledby" aria-labelledby="label1">Content</button>
  <button id="labeled">Content</button>

  <label id="label1">Label1</label>
  <label id="label2">Label2</label>
</div>

<script>
async_test((t) => {
    function accessibleElementById(id) {
        return accessibilityController.accessibleElementById(id);
    }

    window.successCount = 0;
    gotSuccessfulNotification = t.step_func(() => {
        successCount++;
        if (successCount != 4)
            return;

        console.log('All notifications received successfully.');
        accessibleElementById('aria-label').removeNotificationListener();
        accessibleElementById('title').removeNotificationListener();
        accessibleElementById('labelledby').removeNotificationListener();
        accessibleElementById('labeled').removeNotificationListener();

        t.done();
    });

    accessibleElementById('aria-label').setNotificationListener(function(notification) {
        assert_equals(notification, 'MarkDirty');
        gotSuccessfulNotification();
        accessibleElementById('aria-label').unsetNotificationListener();
    });
    document.getElementById('aria-label').setAttribute('aria-label', 'New aria-label');

    accessibleElementById('title').setNotificationListener(function(notification) {
        assert_equals(notification, 'MarkDirty');
        gotSuccessfulNotification();
        accessibleElementById('title').unsetNotificationListener();
    });
    document.getElementById('title').title = 'New title';

    accessibleElementById('labelledby').setNotificationListener(function(notification) {
        assert_equals(notification, 'MarkDirty');
        gotSuccessfulNotification();
        accessibleElementById('labelledby').unsetNotificationListener();
    });
    document.getElementById('labelledby').setAttribute('aria-labelledby', 'label2');

    accessibleElementById('labeled').setNotificationListener(function(notification) {
        assert_equals(notification, 'MarkDirty');
        gotSuccessfulNotification();
        accessibleElementById('labeled').unsetNotificationListener();
    });
    document.getElementById('label1').setAttribute('for', 'labeled');
}, "This test ensures that a change to an element's accessible text, even if indirect, sends a notification.");

</script>

</body>
</html>
